package com.demo.servlet.utils;

import java.util.Calendar;

/**
 * @ProjectName: exerciseApi
 * @Package: com.demo.servlet.utils
 * @ClassName: TimeByCalendar
 * @Author: junku
 * @Description: ${description}
 * @Date: 2021/1/14 17:48
 * @Version: 1.0
 */
public class TimeByCalendar {

    public static String getTimeByCalendar(){
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);//获取年份
        int month=cal.get(Calendar.MONTH)+1;//获取月份
        int day=cal.get(Calendar.DATE);//获取日
        int hour=cal.get(Calendar.HOUR);//小时
        int minute=cal.get(Calendar.MINUTE);//分
        int second=cal.get(Calendar.SECOND);//秒
        int WeekOfYear = cal.get(Calendar.DAY_OF_WEEK);//一周的第几天
        System.out.println("现在的时间是：公元"+year+"年"+month+"月"+day+"日      "+hour+"时"+minute+"分"+second+"秒       星期"+WeekOfYear);
    String dateByCalendar = String.valueOf(year+""+month+""+day+""+hour+""+minute+""+second+""+WeekOfYear);
        return dateByCalendar;
    }

}